/*
 * UnBoundMailBox.cpp
 *
 *  Created on: 13/06/2009
 *      Author: ortal glasman
 */

#include "UnBoundMailBox.h"
#include <queue>
#include <vector>

UnBoundMailBox::UnBoundMailBox(int id)
{
	_Id = id;
	//cout<< _Id <<"'s mailbox size is " << _waiting_msgs.size()<<endl;
}

UnBoundMailBox::~UnBoundMailBox()
{

}

int UnBoundMailBox::getId()
{
	return _Id;
}

void UnBoundMailBox::addFirst(Message* msg)
{
	vector<Message*>::iterator iter = _waiting_msgs.begin();
	_waiting_msgs.insert(iter, msg);
}

void UnBoundMailBox::addLast(Message* msg)
{
	_waiting_msgs.push_back(msg);
}

int UnBoundMailBox::getSize()
{
	return _waiting_msgs.size();
}

Message* UnBoundMailBox::getNextMsg()
{
	Message* nextMsg = _waiting_msgs.at(0);
	_waiting_msgs.erase(_waiting_msgs.begin());
	return nextMsg;
}

bool UnBoundMailBox::isEmpty()
{
	return (_waiting_msgs.size() == 0);
}

void UnBoundMailBox::clear()
{
	_waiting_msgs.clear();
}


